package org.springblade.modules.platform.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import org.springblade.modules.platform.entity.MeasuringChainTable;
import org.springblade.modules.platform.props.HuatengProperties;
import org.springblade.modules.platform.service.IMeasuringChainTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springframework.http.HttpMethod;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/service-huateng-sxdb/handMovement")
@Api(value = "", tags = "手动采集")
@Slf4j
public class HandMovementController {
    private static RestTemplate restTemplate = new RestTemplate();
    private final HuatengProperties huatengProperties;
    private final IMeasuringChainTableService iMeasuringChainTableService;

    @GetMapping("/get")
    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "手动采集", notes = "")
    public R get(@RequestParam(value = "acquisitionFlag") String acquisitionFlag,
                      @RequestParam(value = "chainId") Long chainId) {
        String s = huatengProperties.getStartReadAllData() + "?acquisitionFlag=" + acquisitionFlag + "&chainId=" + chainId;
        try {
            restTemplate.exchange(s, HttpMethod.GET, null, String.class);
            return R.success("成功");
        }catch (Exception e){
            return R.fail("采集失败");
        }
    }

    @GetMapping("/listMeasuring")
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "测量连下拉框", notes = "")
    public R<List<MeasuringChainTable>> list() {
        List<MeasuringChainTable> list = iMeasuringChainTableService.list(Wrappers.<MeasuringChainTable>query().lambda()
                .eq(MeasuringChainTable::getChainCategory, 2)
                .eq(MeasuringChainTable::getIsDeleted, 0));
        return R.data(list);
    }

}
